#ifndef _SMART_DEVICE_GATEWAY_HEAD_H
#define _SMART_DEVICE_GATEWAY_HEAD_H

#include "udp-net-communication.h"
#include "communication-message.h"
#include "communication-worker.h"
#include <thread>
#include <queue>
// 锁
#include <mutex>
// 条件变量
#include <condition_variable>
#include "mqtt-net-communication.h"

using namespace std;

class SmartDeviceGateway
{
public:
    SmartDeviceGateway(const string &uartDevice);
    ~SmartDeviceGateway();
    void start();
    // udp接收数据的子线程函数
    void udpNetCommunicationRun(void);
    void mqttNetCommunicationRun(void);
    // 处理管道内数据的函数
    void commnicationHandlerRun(void);
    void wait(void);
    void notfiy(void);

private:
    UdpNetCommunication *udpNetCommunication;
    MQTTNetCommunication *mqttNetCommunication;
    // udp接收线程
    thread *udpNetThread;
    thread *mqttNetThread;
    // 通讯处理线程
    thread *commnicationHandlerThread;

    // 队列
    queue<CommunicationMessage> messageQueue;

    mutex queueMtx;
    mutex mtx;
    condition_variable cv;
    CommunicationWorker worker;
};

#endif